package com.android.qjpmc.widget.base;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.android.qjpmc.R;
import com.android.qjpmc.databinding.ActivityBaseListBinding;
import com.android.qjpmc.widget.databindingadapter.BaseBindingItemPresenter;
import com.android.qjpmc.widget.databindingadapter.MultiTypeBindingAdapter;
import com.android.qjpmc.widget.mvvm.view.BaseMVVMActivity;
import com.android.qjpmc.widget.mvvm.viewmodel.BaseViewModel;
import com.android.qjpmc.widget.recyclerView.RefreshRecyclerNetConfig;
import com.android.qjpmc.widget.recyclerView.pagemanagestrategy.PageManageBuilder;

/**
 * @Author zhangshuqi
 * @CreateTime 2018/3/22
 * @Describe
 */

public abstract class BaseListActivity<VM extends BaseViewModel, E> extends BaseMVVMActivity<VM, ActivityBaseListBinding> implements BaseBindingItemPresenter<E> {

    protected MultiTypeBindingAdapter mAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_base_list;
    }

    @Override
    public void initView() {

        mAdapter = new MultiTypeBindingAdapter<E>(this, null, getItemLayout());
        PageManageBuilder builder = new PageManageBuilder(this)
                .setAdapter(mAdapter);
        getBuilder(builder);
        mAdapter.setItemPresenter(this);
        mBinding.recyclerView.create(builder);
       // mBinding.recyclerView.setLoadMoreAdapter(mAdapter);
        mBinding.recyclerView.setLoadMoreAdapter(mAdapter, getLayoutManager());
        mBinding.recyclerView.setRefreshRecyclerNetConfig(getRefreshRecyclerNetConfig());

        mBinding.toolbar.setTitleText(getToolbarTitle());
    }

    protected abstract String getToolbarTitle();

    /**
     * 获取到retrofit访问api的配置
     */
    protected abstract RefreshRecyclerNetConfig getRefreshRecyclerNetConfig();

    /**
     * 设置recyclerView的配置类
     */
    protected void getBuilder(PageManageBuilder builder) {

    }

    public RecyclerView.LayoutManager getLayoutManager() {
        return new LinearLayoutManager(this);
    }

    /**
     * 获取到adapter的itemLayout
     */
    protected abstract int getItemLayout();

    @Override
    public void initData() {

    }

    @Override
    public void initEvent() {

    }

    @Override
    protected BaseRefreshViewLayout getRecyclerLayoutView() {
        return mBinding.recyclerView;
    }
}
